<?php
/** 
*
* @package phpBB3
* @version $Id: index.php 53 2007-05-10 21:26:39Z highwayoflife $
* @copyright (c) 2005 phpBB Group 
* @license: for use on Star Trek Guide only. Use/Copy only with permission from startrekguide.com staff.
* @author: Highway of Life - http://startrekguide.com
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

// Start session
$user->session_begin();
$auth->acl($user->data);

$forum_id	= request_var('db', 0);

// Parent forum ID for all MODS
$parent_id = '17';

$sql = 'SELECT style_id FROM ' . STYLES_TABLE . " WHERE style_name = 'Sniper_Blue'";
$db->sql_query($sql, 2678400);
$style = $db->sql_fetchfield('style_id');

$user->setup('mods_database', $style);

// Permissions check for native forum...
if ($forum_id)
{
    if (!$auth->acl_get('f_read', $forum_id))
    {
	   if ($user->data['user_id'] != ANONYMOUS)
	   {
		  trigger_error($user->lang['SORRY_AUTH_READ']);
	   }

	   login_box('', $user->lang['LOGIN_VIEWFORUM']);
    }
}

$sql = 'SELECT left_id, right_id, forum_id, forum_name, forum_desc, forum_desc_bitfield, forum_desc_uid, forum_topics_real
            FROM ' . FORUMS_TABLE . '
            WHERE parent_id = "' . $parent_id . '"';
$result = $db->sql_query($sql);

while ($mod_cat = $db->sql_fetchrow($result))
	{
	$flags = (($config['allow_bbcode']) ? 1 : 0) + (($config['allow_smilies']) ? 2 : 0) + ((true) ? 4 : 0);
	$forum_text = generate_text_for_display($mod_cat['forum_desc'], $mod_cat['forum_desc_uid'], $mod_cat['forum_desc_bitfield'], $flags);
			
    	$template->assign_block_vars('modcat', array(
			'FORUM_DESC'	=> $forum_text,
			'FORUM_NAME'	=> $mod_cat['forum_name'],
			'TOPICS'			=> $mod_cat['forum_topics_real'],
			'U_VIEWFORUM' => append_sid("index.$phpEx", 'db=' . $mod_cat['forum_id']),
			));
		}
$db->sql_freeresult($result);
		
// get MODs from the forum category -- which are the first post of every topic.
$sql = 'SELECT t.topic_id, t.forum_id, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_first_post_id, t.topic_poster, t.topic_first_poster_name, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid
        FROM ' . TOPICS_TABLE . ' t
        LEFT JOIN ' . POSTS_TABLE . ' p ON t.topic_first_post_id = p.post_id
        WHERE t.topic_approved = "1" AND t.forum_id = "' . $forum_id . '"
        ORDER BY t.topic_title ASC';
$resulty = $db->sql_query($sql);

$sql = 'SELECT forum_name
        FROM ' . FORUMS_TABLE . '
        WHERE forum_id = "' . $forum_id . '"';
$result = $db->sql_query($sql);
$forum_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

// Set the page header and load mod category template
page_header($user->lang['VIEW_MODS'] . ' - ' . $forum_data['forum_name']);

// set template filename
$template->set_filenames(array(
	'body' => 'mods_database.html')
);

$links = true;

$template->assign_vars(array(
	'U_DIRECTORY'		=> append_sid("index.$phpEx"),
  'S_DISPLAY_SEARCHBOX'	=> ($auth->acl_get('f_search', $forum_id)) ? true : false,
	'S_SEARCHBOX_ACTION'=> append_sid("{$phpbb_root_path}search.$phpEx", 'fid[]=' . $forum_id),
	'U_MCP'				=> ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;i=main&amp;mode=forum_view", true, $user->session_id) : '',
	'S_NO_MOD'			=> (!$forum_id) ? true : false,
	'U_LINKS'			=> $links,
    ));

while ($mod_data = $db->sql_fetchrow($resulty))
{

    $post_text = $mod_data['post_text'];
    $bbcode_uid = $mod_data['bbcode_uid'];
    $bbcode_bitfield = $mod_data['bbcode_bitfield'];
    
    $parse_text = new parse_message($post_text);
    $parse_text->bbcode_uid = $bbcode_uid;
    $parse_text->bbcode_bitfield = $bbcode_bitfield;
    
    $parse_text->format_display(true, true, true);
    $post_text = $parse_text->message;
    unset($parse_text);
    
    $topic_id = $mod_data['topic_id'];
    
    $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($mod_data['forum_id']) ? $mod_data['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
		
		// Grab the Poll votes...
		$sql = 'SELECT *
				FROM ' . POLL_OPTIONS_TABLE . '
				WHERE topic_id = "' . $topic_id . '"
				ORDER BY poll_option_id ASC ';
		$resultx = $db->sql_query($sql);
		
		$poll_info = array();
		while ($row = $db->sql_fetchrow($result))
		{
			$poll_info[] = $row;
		}
		$db->sql_freeresult($result);
      
    $template->assign_block_vars('modrow', array(
        'TOPIC_TITLE'	=> censor_text($mod_data['topic_title']),
        'TOPIC_TIME'	=> $user->format_date($mod_data['topic_time']),
        'TOPIC_VIEWS'   => $mod_data['topic_views'],
        'TOPIC_AUTHOR'	=> $mod_data['topic_first_poster_name'],
		'TOPIC_REPLIES'	=> $mod_data['topic_replies'],
        'POST_TEXT'     => $post_text,
        'U_VIEW_TOPIC'  => $view_topic_url,
    ));
}
$db->sql_freeresult($resulty);
page_footer();

?>